package coloring.alg;

import org.jgrapht.Graph;
import org.jgrapht.VertexFactory;
import org.jgrapht.generate.RandomGraphGenerator;
import org.jgrapht.graph.SimpleGraph;

import coloring.MyDefaultEdge;
import coloring.vertex.Vertex;

/**
 * Class for graph creating
 * 
 * @author Croaker
 * 
 */
public class GenerateGraph {

	/**
	 * Generates simple graph (drawn below)
	 * 
	 * @return simple graph
	 */
	// a--e--c
	// | | |
	// d--f--b
	public static Graph<Vertex, MyDefaultEdge> genGraph() {
		Graph<Vertex, MyDefaultEdge> graph = new SimpleGraph<Vertex, MyDefaultEdge>(
				MyDefaultEdge.class);

		Vertex a = new Vertex("a");
		Vertex e = new Vertex("e");
		Vertex c = new Vertex("c");
		Vertex d = new Vertex("d");
		Vertex f = new Vertex("f");
		Vertex b = new Vertex("b");

		graph.addVertex(a);
		graph.addVertex(b);
		graph.addVertex(c);
		graph.addVertex(d);
		graph.addVertex(e);
		graph.addVertex(f);

		graph.addEdge(a, e);
		graph.addEdge(e, c);
		graph.addEdge(d, f);
		graph.addEdge(f, b);
		graph.addEdge(a, d);
		graph.addEdge(e, f);
		graph.addEdge(c, b);

		return graph;
	}

	/**
	 * Generates random graph
	 * 
	 * @param vert
	 *            number of vertices in graph
	 * @param edges
	 *            number of edges in graph
	 * @return randomly generated graph
	 */
	public static Graph<Vertex, MyDefaultEdge> genRandomGraph(int vert,
			int edges) {
		VertexFactory<Vertex> factory = new VertexFactory<Vertex>() {
			private int vertNum = 0;

			@Override
			public Vertex createVertex() {
				vertNum++;
				Vertex vertex = new Vertex(Integer.toString(vertNum));
				return vertex;
			}
		};
		RandomGraphGenerator<Vertex, MyDefaultEdge> generator = new RandomGraphGenerator<Vertex, MyDefaultEdge>(
				vert, edges);
		Graph<Vertex, MyDefaultEdge> graph = new SimpleGraph<Vertex, MyDefaultEdge>(
				MyDefaultEdge.class);
		generator.generateGraph(graph, factory, null);
		return graph;
	}

}
